//
//  SHLoginViewController.m
//  Netease
//
//  Created by 王方伟 on 2017/8/17.
//  Copyright © 2017年 wfw. All rights reserved.
//

#import "SHLoginViewController.h"
#import "SHTabBarViewController.h"
#import "SHUserPerfenceTool.h"
#import "NSString+Extension.h"
#import <NIMSDK/NIMSDK.h>

@interface SHLoginViewController ()
@property (strong, nonatomic) IBOutlet UITextField *usernameTextField;
@property (strong, nonatomic) IBOutlet UITextField *passwordTextField;
@end

@implementation SHLoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

- (IBAction)onClickLoginButton:(UIButton *)sender {
    NSString *loginAccount = _usernameTextField.text;
    NSString *loginToken   =  _passwordTextField.text;//[_passwordTextField.text MD5String];
    [[[NIMSDK sharedSDK] loginManager] login:loginAccount token:loginToken completion:^(NSError * _Nullable error) {
        if (error == nil) {
            [SVProgressHUD showSuccess:@"登录成功"];
            SHAccount *account = [[SHAccount alloc] init];
            account.account = loginAccount;
            account.token = loginToken;
            [[SHUserPerfenceTool sharedUserPerfence] saveAccount:account];
            SHTabBarViewController *tabVC = [[SHTabBarViewController alloc] init];
            [UIApplication sharedApplication].keyWindow.rootViewController = tabVC;
        }else{
            [SVProgressHUD showInfo:[NSString stringWithFormat:@"%ld", error.code]];
        }
    }];
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}

- (IBAction)onClickRigistButton:(UIButton *)sender {
    
}

@end
